﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Autenticacao
{
    public partial class frm_ga_eliminaran : Form
    {
        System.Data.SqlClient.SqlConnection con;
        
        public Animal an2;
        public Cliente cl2;
        
        public frm_ga_eliminaran(Animal an1, Cliente cl1)
        {
            this.an2 = an1;
            this.cl2 = cl1;

            InitializeComponent();
        }

        private void cmdga_elanimal_Click(object sender, EventArgs e)
        {
            if (txtga_dtmorte.Text == "" || txtga_dtmorte.Text == "aaaa/MM/dd")
            {
                MessageBox.Show("Tem de inserir a data do óbito!", "Data óbito", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                con = new System.Data.SqlClient.SqlConnection();
                con.ConnectionString = @"Data Source = ANDRÉ-PC\SQLEXPRESS; Initial Catalog = horsepw_bd; Integrated Security = True;";
                con.Open();

                int ida = an2.get_id();
                int idc = cl2.get_id();
                SqlCommand command1 = con.CreateCommand();
                command1.CommandText = "UPDATE Animais SET data_morte = '" + txtga_dtmorte.Text + "', oculto = 1 WHERE id_animal = " + ida + " AND id_cliente = " + idc + ";";
                command1.CommandType = CommandType.Text;

                SqlDataReader reader1 = command1.ExecuteReader();

                MessageBox.Show("Animal removido com sucesso!", "Animal removido", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }
    }
}
